package com.cuit.washneedshake.controller;

import cn.hutool.json.JSONUtil;
import com.cuit.washneedshake.common.BaseResponse;
import com.cuit.washneedshake.common.ErrorCode;
import com.cuit.washneedshake.model.entity.NationalMap;
import com.cuit.washneedshake.service.NationalMapService;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/national-map")
public class NationalMapController {

    @Resource
    private NationalMapService nationalMapService;

    /**
     * 获取地图数据
     * @return
     */
    @GetMapping("/getMap")
    public BaseResponse<String> getNationalMap() {
        List<NationalMap> nationalMapList = nationalMapService.getNationalMapList();
        if (nationalMapList == null) {
            return new BaseResponse<>(ErrorCode.NOT_FOUND_ERROR);
        }
        BaseResponse<String> baseResponse = new BaseResponse<>(ErrorCode.SUCCESS.getCode(), JSONUtil.toJsonStr(nationalMapList));
        return baseResponse;
    }

    /**
     * 获取顶部数据
     * @return
     */
    @GetMapping("/getTop")
    public BaseResponse<String> getNationalMapTop() {
        HashMap<String, Integer> nationalMapTopMap = nationalMapService.getNationalMapTop();
        if (nationalMapTopMap == null) {
            return new BaseResponse<>(ErrorCode.NOT_FOUND_ERROR);
        }
        BaseResponse<String> baseResponse = new BaseResponse<>(ErrorCode.SUCCESS.getCode(), JSONUtil.toJsonStr(nationalMapTopMap));
        return baseResponse;
    }
}
